﻿using System;
using UnityEngine;
using UnityEngine.EventSystems;

//UI与场景点击交互
public class TouchScene:MonoBehaviour
{
    GameObject _root;
    public Action<RaycastHit> HiStnCallback;
    public int UnTouchLayer;
    public TouchScene()
    {
        _root =UIMgr.GetInstance().Add("UI/FightUI/TouchScene",UILayer.Touch);
        var touchEx = _root.GetComponent<TouchEx>();
        touchEx.PointUpCallback += onTouchScene;
       
    }


    private void onTouchScene(PointerEventData eventData)
    {
        //Debug.Log("点击事件 ");
        Ray ray = CameraControll.Instance.GetComponent<Camera>().ScreenPointToRay(eventData.position);

        RaycastHit ret;
        if (Physics.Raycast(ray, out ret, float.MaxValue,~(1 << UnTouchLayer)))
        {
            //Debug.Log(ret.point);
            if (HiStnCallback != null)
                HiStnCallback(ret);
        }
    }
}
